<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="产品id" prop="productId">-->
<!--        <el-input-->
<!--          v-model="queryParams.productId"-->
<!--          placeholder="请输入产品id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="openid" prop="openid">-->
<!--        <el-input-->
<!--          v-model="queryParams.openid"-->
<!--          placeholder="请输入openid"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="支付Body" prop="payBody">-->
<!--        <el-input-->
<!--          v-model="queryParams.payBody"-->
<!--          placeholder="请输入支付Body"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="金额" prop="totalFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.totalFee"-->
<!--          placeholder="请输入金额"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="订单号" prop="outTradeNo">
        <el-input
          v-model="queryParams.outTradeNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="付款ip" prop="spbillCreateIp">-->
<!--        <el-input-->
<!--          v-model="queryParams.spbillCreateIp"-->
<!--          placeholder="请输入付款ip"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="交易号" prop="transactionId">
        <el-input
          v-model="queryParams.transactionId"
          placeholder="请输入交易号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.fo_diligence_report_order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="人工报告" prop="report1Path">-->
<!--        <el-input-->
<!--          v-model="queryParams.report1Path"-->
<!--          placeholder="请输入人工报告"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="AI报告" prop="report2Path">-->
<!--        <el-input-->
<!--          v-model="queryParams.report2Path"-->
<!--          placeholder="请输入AI报告"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="ext1" prop="ext1">-->
<!--        <el-input-->
<!--          v-model="queryParams.ext1"-->
<!--          placeholder="请输入ext1"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="ext2" prop="ext2">-->
<!--        <el-input-->
<!--          v-model="queryParams.ext2"-->
<!--          placeholder="请输入ext2"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="ext3" prop="ext3">-->
<!--        <el-input-->
<!--          v-model="queryParams.ext3"-->
<!--          placeholder="请输入ext3"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="ext4" prop="ext4">-->
<!--        <el-input-->
<!--          v-model="queryParams.ext4"-->
<!--          placeholder="请输入ext4"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="ext5" prop="ext5">-->
<!--        <el-input-->
<!--          v-model="queryParams.ext5"-->
<!--          placeholder="请输入ext5"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['yipaiju:diligence_report_order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['yipaiju:diligence_report_order:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['yipaiju:diligence_report_order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['yipaiju:diligence_report_order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="diligence_report_orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="ID" align="center" prop="id" />-->
<!--      <el-table-column label="产品id" align="center" prop="productId" />-->
      <el-table-column label="openid" align="center" prop="openid" />
      <el-table-column label="支付Body" align="center" prop="payBody" />
      <el-table-column label="金额" align="center" prop="totalFee" />
      <el-table-column label="订单号" align="center" prop="outTradeNo" />
<!--      <el-table-column label="付款ip" align="center" prop="spbillCreateIp" />-->
      <el-table-column label="交易号" align="center" prop="transactionId" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fo_diligence_report_order_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="人工报告" align="center" prop="report1Path" />
      <el-table-column label="AI报告" align="center" prop="report2Path" />
<!--      <el-table-column label="ext1" align="center" prop="ext1" />-->
<!--      <el-table-column label="ext2" align="center" prop="ext2" />-->
<!--      <el-table-column label="ext3" align="center" prop="ext3" />-->
<!--      <el-table-column label="ext4" align="center" prop="ext4" />-->
<!--      <el-table-column label="ext5" align="center" prop="ext5" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yipaiju:diligence_report_order:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yipaiju:diligence_report_order:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="generatePdf(scope.row)"
            v-hasPermi="['yipaiju:diligence_report_order:generate_pdf']"
          >生成报告</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-share"
            @click="sendPdf(scope.row)"
            v-hasPermi="['yipaiju:diligence_report_order:send_pdf']"
          >发送报告</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改尽调报告订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<!--        <el-form-item label="产品id" prop="productId">-->
<!--          <el-input v-model="form.productId" placeholder="请输入产品id" />-->
<!--        </el-form-item>-->
        <el-form-item label="openid" prop="openid">
          <el-input v-model="form.openid" placeholder="请输入openid" />
        </el-form-item>
        <el-form-item label="支付Body" prop="payBody">
          <el-input v-model="form.payBody" placeholder="请输入支付Body" />
        </el-form-item>
        <el-form-item label="金额" prop="totalFee">
          <el-input v-model="form.totalFee" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="订单号" prop="outTradeNo">
          <el-input v-model="form.outTradeNo" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="付款ip" prop="spbillCreateIp">
          <el-input v-model="form.spbillCreateIp" placeholder="请输入付款ip" />
        </el-form-item>
        <el-form-item label="交易号" prop="transactionId">
          <el-input v-model="form.transactionId" placeholder="请输入交易号" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.fo_diligence_report_order_status"
              :key="dict.value"
              :label="dict.label"
:value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="人工报告" prop="report1Path">
<!--          <el-input v-model="form.report1Path" placeholder="请输入人工报告" />-->
          <file-upload v-model="form.report1Path" :limit="1" file-size="100" :file-type="['pdf']"></file-upload>
        </el-form-item>
        <el-form-item label="AI报告" prop="report2Path">
<!--          <el-input v-model="form.report2Path" placeholder="请输入AI报告" />-->
          <file-upload v-model="form.report2Path" :limit="1" file-size="100" :file-type="['pdf']"></file-upload>
        </el-form-item>
<!--        <el-form-item label="ext1" prop="ext1">-->
<!--          <el-input v-model="form.ext1" placeholder="请输入ext1" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="ext2" prop="ext2">-->
<!--          <el-input v-model="form.ext2" placeholder="请输入ext2" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="ext3" prop="ext3">-->
<!--          <el-input v-model="form.ext3" placeholder="请输入ext3" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="ext4" prop="ext4">-->
<!--          <el-input v-model="form.ext4" placeholder="请输入ext4" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="ext5" prop="ext5">-->
<!--          <el-input v-model="form.ext5" placeholder="请输入ext5" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDiligence_report_order, getDiligence_report_order, delDiligence_report_order, addDiligence_report_order, updateDiligence_report_order, manuallGenerateReport, manuallSendMessage } from "@/api/yipaiju/diligence_report_order";

export default {
  name: "Diligence_report_order",
  dicts: ['fo_diligence_report_order_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 尽调报告订单表格数据
      diligence_report_orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productId: null,
        openid: null,
        payBody: null,
        totalFee: null,
        outTradeNo: null,
        spbillCreateIp: null,
        transactionId: null,
        status: null,
        report1Path: null,
        report2Path: null,
        ext1: null,
        ext2: null,
        ext3: null,
        ext4: null,
        ext5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询尽调报告订单列表 */
    getList() {
      this.loading = true;
      listDiligence_report_order(this.queryParams).then(response => {
        this.diligence_report_orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        productId: null,
        openid: null,
        payBody: null,
        totalFee: null,
        outTradeNo: null,
        spbillCreateIp: null,
        transactionId: null,
        status: null,
        report1Path: null,
        report2Path: null,
        ext1: null,
        ext2: null,
        ext3: null,
        ext4: null,
        ext5: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加尽调报告订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDiligence_report_order(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改尽调报告订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDiligence_report_order(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDiligence_report_order(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除尽调报告订单编号为"' + ids + '"的数据项？').then(function() {
        return delDiligence_report_order(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    generatePdf(row){
      const id = row.id;
      this.$modal.confirm('是否确认生成尽调报告订单编号为"' + id + '"的数据项？').then(function() {
        return manuallGenerateReport(id);
      }).then(() => {
        this.$modal.msgSuccess("后台努力生成中。。。");
      }).catch(() => {});
    },
    sendPdf(row){
      const id = row.id;
      this.$modal.confirm('是否确认发送尽调报告订单编号为"' + id + '"的数据项？').then(function() {
        return manuallSendMessage(id);
      }).then(() => {
        this.$modal.msgSuccess("报告发送成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yipaiju/diligence_report_order/export', {
        ...this.queryParams
      }, `diligence_report_order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
